<?php
require_once '../inc/configuration.php';
require_once '../inc/connexion_bdd.php';


$order = isset($_GET['ordre']) ? "ORDER BY rdv_date ".$_GET['ordre']." , heure ".$_GET['ordre'] : "";
$sql = "SELECT * FROM rendez_vous ".$order;
$envoi_requete=  mysqli_query($connexion_serveur,$sql );
$nbre_total = mysqli_num_rows($envoi_requete);
?>
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title>Rendez-vous</title>
        <?php require_once "../inc/css_bootstrap.php" ?>
        <style>
            .table {
                width: 500px;
            }
            
            th {
                width: 35%;
                text-align: right;
            }
        </style>
    </head>
    <body>
        <?php require_once '../inc/menu_principal.php'; ?>
        
        <h1>LISTE DES RENDEZ-VOUS</h1>
        <div style="margin:15px;">Nombre de rendez-vous affichés : <?php echo $nbre_total; ?></div>
        <?php
        while ($resultats = mysqli_fetch_array($envoi_requete)) {
        ?>
        <div>
            <table class="table table-bordered">
                <tr class="active">
                    <th>N°</th>
                    <td>  <?php echo $resultats['id']?>
                        <div class="btn-group" style="float: right;">
                            <button type="button" class="btn btn-warning btn-xs" data-toggle="dropdown">
                                Action
                                <button type="button" class="btn btn-warning btn-xs dropdown-toggle" data-toggle="dropdown">
                                    <span class="caret"></span>
                                    <span class="sr-only">Toggle Dropdown</span>
                                </button>
                            </button>
                            <ul class="dropdown-menu" role="menu">
                                <li><a href="modifier_rdv.php?id=<?php echo $resultats["id"]; ?>">Modifier</a></li>
                                <li><a href="supprimer_rdv.php?action=1&id=<?php echo $resultats["id"]; ?>">Supprimer</a></li>
                            </ul>
                        </div>
                    </td>
                </tr>
                <tr>
                    <th>Contact</th>
                    <td><?php 
                        //REQUETE SQL
                        $sql_cont = "SELECT nom, prenom FROM contacts WHERE id=".$resultats["id"];
                        $req_cont = mysqli_query($connexion_serveur, $sql_cont);
                        $data_cont = mysqli_fetch_assoc($req_cont);
                        
                        echo $data_cont["nom"]." ".$data_cont["prenom"];
                        
                        ?>
                        
                            </td>
                </tr>
                <tr>
                    <th>Date</th>
                    <td>  <?php echo $resultats['rdv_date']?></td>
                </tr>
                <tr>
                    <th>Heure</th>
                    <td>  <?php echo $resultats['heure']?></td>
                </tr>
                <tr>
                    <th>Type de Rendez-Vous</th>
                    <td>  <?php echo $resultats['type_rdv']?></td>
                </tr>
                <tr>
                    <th>Objet</th>
                    <td>  <?php echo $resultats['objet']?></td>
                </tr>
                <tr>
                    <th>Observations</th>
                    <td>  <?php echo $resultats['observations']?></td>
                </tr>
                
            </table>
        </div>
     <?php
        }
        ?>


        
          
         
</html>